using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Camera_Ctrl : Singleton_Base<Camera_Ctrl>
{
    public override bool isDontDestroy => false;
    public bool isActive = true;
    public Transform target;
    public float smoothTime = 0.16f;
    public Vector3 moveHorizontalVelocity;
    public Vector3 moveVerticalVelocity;
    public CameraLimit_Ctrl limit_Ctrl;
    // Start is called before the first frame update
    void Start()
    {
        
    }
    private void Update()
    {
        Run();
    }
    // Update is called once per frame
    void LateUpdate()
    {
        //Time.fixedDeltaTime = Time.deltaTime;
        //Run();
    }
    public void Run()
    {
        if (isActive && target != null)
        {
            Vector3 targetPos = target.transform.position;
            if (limit_Ctrl != null)
            {
                targetPos.x = Mathf.Clamp(targetPos.x, limit_Ctrl.minPos.x, limit_Ctrl.maxPos.x);
                targetPos.y = Mathf.Clamp(targetPos.y, limit_Ctrl.minPos.y, limit_Ctrl.maxPos.y);
            }
            targetPos = Vector3.SmoothDamp(this.transform.position, targetPos, ref moveHorizontalVelocity, smoothTime);
            //targetPos = target.transform.position;
            targetPos.z = -10;
            this.transform.position = targetPos;
        }
    }
    public void ResetPos()
    {
        if (isActive && target != null)
        {
            Vector3 targetPos = target.transform.position;
            targetPos.z = -10;
            moveHorizontalVelocity = Vector3.zero;
            this.transform.position = targetPos;
        }
    }

}
